package com.atguigu.gmall.product.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategoryView;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.mapper.SpuInfoMapper;
import com.atguigu.gmall.product.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Api(tags = "商品详情管理")
@RestController
@RequestMapping("/api/product")
public class ApiProductController {

    @Autowired
    private BaseManageService baseManageService;

    @Autowired
    private SkuInfoService skuInfoService;

    @Autowired
    private SpuInfoService spuInfoService;

    @Autowired
    private SkuSaleAttrValueService skuSaleAttrValueService;

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    /**
     * 查询商品详情信息
     * @param skuId
     * @return
     */
    @ApiOperation("查询商品详情信息")
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public Result<SkuInfo> getSkuInfo(@PathVariable("skuId") Long skuId) {
        SkuInfo skuInfo = skuInfoService.getSkuInfo(skuId);
        return Result.ok(skuInfo);
    }

    /**
     * 商品导航
     * @param category3Id
     * @return
     */
    @ApiOperation("商品导航链接")
    @GetMapping("/inner/getCategoryView/{category3Id}")
    public Result<BaseCategoryView> getCategoryView(@PathVariable("category3Id") Long category3Id) {
        BaseCategoryView categoryViewByCategory3Id = baseManageService.getCategoryViewByCategory3Id(category3Id);
        return Result.ok(categoryViewByCategory3Id);
    }

    /**
     * 获取商品价格
     * @param skuId
     * @return
     */
    @ApiOperation("获取商品价格")
    @GetMapping("/inner/getSkuPrice/{skuId}")
    public Result<BigDecimal> getSkuPrice(@PathVariable("skuId") Long skuId) {
        BigDecimal skuPrice = skuInfoService.getSkuPrice(skuId);
        return Result.ok(skuPrice);
    }

    /**
     * 获取商品组合  标记sku
     * @param skuId
     * @param spuId
     * @return
     */
    @ApiOperation("获取商品组合")
    @GetMapping("/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public Result<List<SpuSaleAttr>> getSpuSaleAttrListCheckBySku(@PathVariable("skuId") Long skuId, @PathVariable("spuId") Long spuId) {
        List<SpuSaleAttr> spuSaleAttr = spuInfoService.getSpuSaleAttrListCheckBySku(skuId, spuId);
        return Result.ok(spuSaleAttr);
    }

    /**
     * 获取sku组合切换依据
     * @param spuId
     * @return
     */
    @ApiOperation("获取sku组合切换依据")
    @GetMapping("/inner/getSkuValueIdsMap/{spuId}")
    public Result<Map<String, Long>> getSkuValueIdsMap(@PathVariable("spuId") Long spuId) {
        Map<String, Long> skuAttrMap = skuSaleAttrValueService.getSkuValueIdsMap(spuId);
        return Result.ok(skuAttrMap);
    }

    /**
     * 获取所有分类 显示到页面
     * @return
     */
    @GetMapping("/inner/get/all/category/for/portal")
    public Result<List<JSONObject>> getAllCategoryForPortal() {
        List<JSONObject> baseCategoryList = baseManageService.getBaseCategoryList();
        return Result.ok(baseCategoryList);
    }

    @GetMapping("/inner/getAttrList/{skuId}")
    public Result<List<BaseAttrInfo>> getAttrListBySkuId(@PathVariable("skuId") Long skuId) {
        List<BaseAttrInfo> baseAttrInfoList = baseAttrInfoService.getAttrListBySkuId(skuId);
        return Result.ok(baseAttrInfoList);
    }






}
